<template>
    <div class="search-container">
      <!-- 搜索框 -->
      <div class="search-box">
        <div class="search-logo">心理搜索</div>
        <div class="search-input-container">
          <el-input
            v-model="searchQuery"
            placeholder="请输入病例"
            @keyup.enter="handleSearch"
            @input="handleInputChange"
            class="search-input"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
          <el-button type="primary" @click="handleSearch" class="search-button">搜索</el-button>
        </div>
      </div>
  
      <!-- 猜你想搜 -->
      <div v-if="showSuggestions" class="suggestions-section">
        <div class="section-title">猜你想搜</div>
        <div class="suggestion-tags">
          <el-tag
            v-for="(tag, index) in quickSuggestions"
            :key="index"
            @click="selectSuggestion(tag)"
            class="suggestion-tag"
          >
            {{ tag }}
          </el-tag>
        </div>
      </div>
  
      <!-- 热门搜索 -->
      <div v-if="showSuggestions" class="hot-search-section">
        <div class="section-title">热门搜索</div>
        <div class="hot-search-list">
          <div
            v-for="(item, index) in hotSearches"
            :key="index"
            @click="selectHotSearch(item)"
            class="hot-search-item"
          >
            <span class="hot-search-index">{{ index + 1 }}.</span>
            <span class="hot-search-text">{{ item }}</span>
          </div>
        </div>
      </div>
  
      <!-- 搜索提示 -->
      <div v-if="searchPerformed" class="search-tip">
        <p>正在跳转到百度搜索 "<strong>{{ searchQuery }}</strong>"...</p>
        <p>如果没有自动跳转，请<a href="#" @click.prevent="openBaiduSearch">点击这里</a></p>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, computed } from 'vue'
  import { Search } from '@element-plus/icons-vue'
  
  const searchQuery = ref('')
  const showSuggestions = ref(true)
  const searchPerformed = ref(false)
  
  // 猜你想搜数据
  const quickSuggestions = ref([
    '情感障碍', '厌学症', 
    '抑郁症', '精神分裂症'
  ])
  
  // 热门搜索数据
  const hotSearches = ref([
    '精神分裂症',
    '双向情感障碍',
    '强迫症',
    '注意力缺陷多动症',
    '社交恐惧症',
    '焦虑障碍'
  ])
  
  // 处理搜索
  const handleSearch = () => {
    if (searchQuery.value.trim()) {
      searchPerformed.value = true
      openBaiduSearch()
    }
  }
  
  // 输入变化处理
  const handleInputChange = () => {
    if (!searchQuery.value) {
      showSuggestions.value = true
      searchPerformed.value = false
    }
  }
  
  // 选择建议
  const selectSuggestion = (suggestion) => {
    searchQuery.value = suggestion
    handleSearch()
  }
  
  // 选择热门搜索
  const selectHotSearch = (item) => {
    searchQuery.value = item
    handleSearch()
  }
  
  // 打开百度搜索
  const openBaiduSearch = () => {
    window.open(`https://www.baidu.com/s?wd=${encodeURIComponent(searchQuery.value)}`, '_blank')
  }
  </script>
  
  <style scoped>
  .search-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    background-color: #f5f7fa;
  }
  
  .search-box {
    text-align: center;
    margin-bottom: 30px;
  }
  
  .search-logo {
    font-size: 32px;
    font-weight: bold;
    color: #3385ff;
    margin-bottom: 20px;
  }
  
  .search-input-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
  }
  
  .search-input {
    width: 500px;
  }
  
  .search-input :deep(.el-input__inner) {
    height: 40px;
    border-radius: 20px;
    padding-left: 20px;
  }
  
  .search-button {
    height: 40px;
    border-radius: 20px;
    padding: 0 20px;
  }
  
  .section-title {
    font-size: 16px;
    color: #999;
    margin-bottom: 15px;
    padding-left: 10px;
  }
  
  .suggestions-section {
    margin-bottom: 30px;
  }
  
  .suggestion-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  
  .suggestion-tag {
    cursor: pointer;
    border-radius: 15px;
    padding: 8px 15px;
  }
  
  .hot-search-list {
    background-color: #fff;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  }
  
  .hot-search-item {
    padding: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
  }
  
  .hot-search-item:last-child {
    border-bottom: none;
  }
  
  .hot-search-item:hover {
    background-color: #f5f7fa;
  }
  
  .hot-search-index {
    color: #3385ff;
    margin-right: 10px;
    font-weight: bold;
  }
  
  .hot-search-text {
    flex: 1;
  }
  
  .search-tip {
    margin-top: 30px;
    padding: 20px;
    background-color: #fff;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  }
  
  .search-tip a {
    color: #3385ff;
    text-decoration: none;
  }
  
  .search-tip a:hover {
    text-decoration: underline;
  }
  
  /* 响应式设计 */
  @media (max-width: 768px) {
    .search-container {
      padding: 15px;
    }
    
    .search-input {
      width: 100%;
    }
    
    .search-input-container {
      flex-direction: column;
    }
    
    .search-button {
      width: 100%;
    }
  }
  </style>